Add Tom Paton's change to discard points without timestamps in the track
authorrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 14 May 2012 13:44:27 +0000 (13:44 +0000)
committerrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 14 May 2012 13:44:27 +0000 (13:44 +0000)
filter.

There's the minor detail that it breaks testo.  We'll work on that.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4174 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/reference/track/trackfilter_discard.gpx [new file with mode: 0755]
gpsbabel/reference/track/trackfilter_discard_out.gpx [new file with mode: 0644]
gpsbabel/testo.d/track-discard.test [new file with mode: 0644]
gpsbabel/trackfilter.c
gpsbabel/xmldoc/filters/options/track-discard.xml [new file with mode: 0644]

diff --git a/gpsbabel/reference/track/trackfilter_discard.gpx b/gpsbabel/reference/track/trackfilter_discard.gpx
new file mode 100755 (executable)
index 0000000..efe60fd
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx
+  version="1.0"
+  creator="GPSBabel - http://www.gpsbabel.org"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns="http://www.topografix.com/GPX/1/0"
+  xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
+<time>2012-04-17T08:26:58Z</time>
+<bounds minlat="-36.722941300" minlon="142.175800700" maxlat="-36.716685300" maxlon="142.198467900"/>
+<trk>
+  <name>Track 937</name>
+  <desc>14/04/2012  3:54 pm</desc>
+<trkseg>
+<trkpt lat="-36.720798700" lon="142.177066800">
+  <ele>145.411000</ele>
+  <time>2012-04-14T07:08:11.906Z</time>
+</trkpt>
+<trkpt lat="-36.720713300" lon="142.176767600">
+  <ele>145.683000</ele>
+  <time>2012-04-14T07:08:11.906Z</time>
+</trkpt>
+<trkpt lat="-36.720713300" lon="142.176767600">
+  <ele>145.808000</ele>
+</trkpt>
+<trkpt lat="-36.720796000" lon="142.176806200">
+  <ele>145.736000</ele>
+  <time>2012-04-14T07:09:35.906Z</time>
+</trkpt>
+</trkseg>
+</trk>
+</gpx>
diff --git a/gpsbabel/reference/track/trackfilter_discard_out.gpx b/gpsbabel/reference/track/trackfilter_discard_out.gpx
new file mode 100644 (file)
index 0000000..3238d0d
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx
+  version="1.0"
+  creator="GPSBabel - http://www.gpsbabel.org"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns="http://www.topografix.com/GPX/1/0"
+  xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
+<time>1970-01-01T00:00:00Z</time>
+<bounds minlat="-36.720798700" minlon="142.176806200" maxlat="-36.720796000" maxlon="142.177066800"/>
+<trk>
+  <name>Track 937</name>
+  <desc>14/04/2012  3:54 pm</desc>
+<trkseg>
+<trkpt lat="-36.720798700" lon="142.177066800">
+  <ele>145.411000</ele>
+  <time>2012-04-14T07:08:11.906Z</time>
+</trkpt>
+</trkseg>
+<trkseg>
+<trkpt lat="-36.720796000" lon="142.176806200">
+  <ele>145.736000</ele>
+  <time>2012-04-14T07:09:35.906Z</time>
+</trkpt>
+</trkseg>
+</trk>
+</gpx>
diff --git a/gpsbabel/testo.d/track-discard.test b/gpsbabel/testo.d/track-discard.test
new file mode 100644 (file)
index 0000000..91da31a
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# tracks filter merge,discard option tests
+#
+
+rm -f ${TMPDIR}/discard*
+
+# gpx file with points with missing timestamps (has 4 trkpts, 2 duplicate times, 1 missing time, expect merge to output 2 valid trkpts)
+# expecting this to fail during a standard -x track,merge so call directly rather than via gpsbabel function
+${PNAME} -t -i gpx -f ${REFERENCE}/track/trackfilter_discard.gpx -x track,merge -o csv -F - && {
+         echo "$PNAME succeeded! (it shouldn't have with this input...)"
+}
+# ... but should get through if we discard the points.
+gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter_discard.gpx -x track,merge,discard -o gpx -F ${TMPDIR}/discard.gpx
+compare ${REFERENCE}/track/trackfilter_discard_out.gpx ${TMPDIR}/discard.gpx
index f70161f44444ab47150d68d28e84d47e35ddbec9..140a0eaa157fe5878d26c36f05c5640302c60737 100644 (file)
@@ -34,6 +34,7 @@
        (based on patch from Vladimir Kondratiev)
    2007-07-26: Allow 'range' together with trackpoints without timestamp
    2010-06-02: Add specified timestamp to each trackpoint (added by sven_luzar)
+   2012-05-04: Added 'discard' option to 'merge' to throw out track points without timestamp
 */
 
 #include <ctype.h>
@@ -62,6 +63,7 @@
 #define TRACKFILTER_TRK2SEG_OPTION      "trk2seg"
 #define TRACKFILTER_SEGMENT_OPTION      "segment"
 #define TRACKFILTER_FAKETIME_OPTION     "faketime"
+#define TRACKFILTER_DISCARD_OPTION      "discard"
 
 #undef TRACKF_DBG
 
@@ -81,6 +83,7 @@ static char *opt_seg2trk = NULL;
 static char *opt_trk2seg = NULL;
 static char *opt_segment = NULL;
 static char *opt_faketime = NULL;
+static char *opt_discard = NULL;
 
 static
 arglist_t trackfilter_args[] = {
@@ -160,6 +163,11 @@ arglist_t trackfilter_args[] = {
     "Add specified timestamp to each trackpoint",
     NULL, ARGTYPE_STRING, ARG_NOMINMAX
   },
+  {
+    TRACKFILTER_DISCARD_OPTION,  &opt_discard,  
+    "Discard track points without timestamps during merge",
+    NULL, ARGTYPE_BOOL, ARG_NOMINMAX
+  },
   ARG_TERMINATOR
 };
 
@@ -173,6 +181,7 @@ typedef struct trkflt_s {
 static trkflt_t *track_list = NULL;
 static int track_ct = 0;
 static int track_pts = 0;
+static int timeless_pts = 0;
 static int opt_interval = 0;
 static int opt_distance = 0;
 static char need_time;         /* initialized within trackfilter_init */
@@ -325,7 +334,8 @@ trackfilter_fill_track_list_cb(const route_head *track)     /* callback for track_d
     track_pts++;
 
     wpt = (waypoint *)elem;
-    if ((need_time != 0) && (wpt->creation_time == 0)) {
+    if(wpt->creation_time == 0) timeless_pts++;
+    if (!(opt_merge && opt_discard) && (need_time != 0) && (wpt->creation_time == 0)) {
       fatal(MYNAME "-init: Found track point at %f,%f without time!\n",
             wpt->latitude, wpt->longitude);
     }
@@ -483,18 +493,20 @@ trackfilter_merge(void)
   waypoint *prev, *wpt;
   route_head *master = track_list[0].track;
 
-  if (track_pts < 1) {
+  if (track_pts-timeless_pts < 1) {
     return;
   }
 
-  buff = (waypoint **)xcalloc(track_pts, sizeof(*buff));
+  buff = (waypoint **)xcalloc(track_pts-timeless_pts, sizeof(*buff));
 
   j = 0;
   for (i = 0; i < track_ct; i++) {     /* put all points into temp buffer */
     route_head *track = track_list[i].track;
     QUEUE_FOR_EACH((queue *)&track->waypoint_list, elem, tmp) {
       wpt = (waypoint *)elem;
-      buff[j++] = waypt_dupe(wpt);
+      if(wpt->creation_time != 0) {
+        buff[j++] = waypt_dupe(wpt);
+      }
       track_del_wpt(track, wpt);
       waypt_free(wpt);
     }
@@ -504,12 +516,12 @@ trackfilter_merge(void)
   }
   track_ct = 1;
 
-  qsort(buff, track_pts, sizeof(*buff), trackfilter_merge_qsort_cb);
+  qsort(buff, track_pts-timeless_pts, sizeof(*buff), trackfilter_merge_qsort_cb);
 
-  dropped = 0;
+  dropped = timeless_pts;
   prev = NULL;
 
-  for (i = 0; i < track_pts; i++) {
+  for (i = 0; i < track_pts-timeless_pts; i++) {
     wpt = buff[i];
     if ((prev == NULL) || (prev->creation_time != wpt->creation_time)) {
       route_add_wpt(master, wpt);
diff --git a/gpsbabel/xmldoc/filters/options/track-discard.xml b/gpsbabel/xmldoc/filters/options/track-discard.xml
new file mode 100644 (file)
index 0000000..c654609
--- /dev/null
@@ -0,0 +1,12 @@
+<para> 
+This option is used in conjunction with the merge option to discard track points with missing
+timestamps instead of aborting with the "Found track point at lat,lon without time!" error.
+</para>
+<example id="ex_track_discard">
+<title>Merging tracks with missing timestamps with the track filter</title>
+<para> 
+Suppose you want to merge tracks that may have missing timestamps.  To do that, use this command line:
+</para>
+<para><userinput>gpsbabel -t -i gpx -f john.gpx -f doe.gpx -x track,merge,discard -o gpx -F john_doe.gpx</userinput></para>
+</example>
+